﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows8Accelerator.Core.Xaml.Helpers;
using Windows8Accelerator.Core.Xaml.Html;

namespace Windows8Accelerator.Core.Xaml.Controls.RichText
{
    public class AVisitor : ControlVisitor
    {
        public AVisitor(SuperHtmlNode superHtmlNode, SuperHtmlNodeVisitor parentVisitor)
            : base(superHtmlNode, parentVisitor)
        {
            VisitChildren = true;
        }

        protected override void InternalVisitNode1(SuperHtmlNode htmlNode)
        {
            if (htmlNode.Attributes.ContainsKey("href"))
            {
                AddLineBreakingIfNecessary();
                if (State.RequiresLeadingSpace && State.HasContent)
                {
                    AddRun(" ");
                }

                if (htmlNode.Attributes.ContainsKey("href"))
                {
                    var href = HtmlHelperBase.Instance.ConvertToText(htmlNode.Attributes["href"]).Replace("\"", "");
                    if (!string.IsNullOrEmpty(href))
                        AddA(href);
                }
            }
        }
    }
}
